package com.go.ssh.point.service.impl;

import com.go.ssh.commons.service.impl.BaseServiceImpl;
import com.go.ssh.point.dao.IAccountDao;
import com.go.ssh.point.exception.UserExistsException;
import com.go.ssh.point.exception.UserNotFoundException;
import com.go.ssh.point.model.UserModel;
import com.go.ssh.point.service.IAccountService;

public class AccountServiceImpl extends BaseServiceImpl<UserModel, Integer>
		implements IAccountService {

	@Override
	public UserModel login(UserModel user) throws UserNotFoundException {
		UserModel loggedInUser = getUserDao().get(user.getUsername(),
				user.getPassword());
		if (null == loggedInUser)
			throw new UserNotFoundException();

		return loggedInUser;
	}

	@Override
	public UserModel register(UserModel user) throws UserExistsException {
		UserModel user1 = getUserDao().get(user.getUsername());
		if (user1 != null)
			throw new UserExistsException();

		getUserDao().save(user);
		return user;
	}

	IAccountDao getUserDao() {
		return (IAccountDao) getDao();
	}
}
